import { baseUrl } from "./env";

import axios from "axios";

const service = axios.create({
    baseURL: baseUrl,
    timeout: 5000
})

//添加请求拦截器
service.interceptors.request.use(
    //发送请求前做些什么
    config => {
        return config
    },
    //发生错误做些什么
    error => {
        console.log(error);
        return Promise.reject()
    }
)

//添加相应拦截器
service.interceptors.response.use(
    //对响应数据做点什么
    response => {
        if (response.status === 200) {
            return response.data
        } else {
            Promise.reject()
        }
    },
    //响应错误做点什么
    error => {
        console.log(error);
        return Promise.reject()
    }
)

export default service